package engine.ui
{
	import engine.control.MenuList;
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ObjectData;
	import engine.data.View;
	import newx.utils.FilterUtil;
	import engine.flag.GameDefine;
	import engine.logic.tips.TipsManage;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.scene.SceneManager;
	import engine.ui.AlertUI;
	import engine.ui.equipStrenGthen.EquipComposeLogic;
	import engine.ui.equipStrenGthen.EquipEnchaseLogic;
	import engine.ui.equipStrenGthen.EquipLeachLogic;
	import engine.ui.equipStrenGthen.EquipProtectionLogic;
	import engine.ui.equipStrenGthen.EquipStilettoLogic;
	import engine.ui.equipStrenGthen.EquipUnenchaseLogic;
	import engine.ui.equipStrenGthen.EquipUpLogic;
	import engine.ui.equipStrenGthen.IEquipLogic;
	import engine.ui.equipStrenGthen.RockChangeLogic;
	import engine.ui.lite.BaseUI;
	import engine.ui.UIManage;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import newx.BaseObject;
	import newx.com.control.button.NxButton;
	import newx.com.control.group.NxViewGroup;
	import newx.com.control.NxClip;
	import newx.com.control.radio.NxRadio;
	import newx.com.control.tab.NxTab;
	import newx.com.control.table.NxTable;
	import newx.com.control.text.NxLabel;
	import newx.com.control.text.NxText;
	import newx.com.config.StaticIni
	import newx.com.control.tab.NxTabEvent
	import newx.com.control.window.NxWindowEvent
	
	/**
	 * ...
	 * @author ...WangHaiBo
	 * ...........www.woniu.com
	 * 新版装备强化功能
	 */
	public class NewItemChangeUI extends BaseUI
	{
		public var parent1:MovieClip;
		public var border_left_1:MovieClip
		public var lab_equipname_1:NxLabel
		public var viewgroup_left_1:NxViewGroup
		public var hole1_pic_1:MovieClip
		public var hole2_pic_1:MovieClip
		public var hole3_pic_1:MovieClip
		public var hole4_pic_1:MovieClip
		public var hole1_lab_1:NxLabel
		public var hole2_lab_1:NxLabel
		public var hole3_lab_1:NxLabel
		public var hole4_lab_1:NxLabel
		public var lab_succeedpercent_1:NxLabel
		public var lab_needmoney_1:NxLabel
		public var btn_star_1:NxButton
		
		public var parent2:MovieClip
		public var border_left_2:MovieClip
		public var lab_equipname_2:NxLabel
		public var viewgroup_left2_1:NxViewGroup
		public var lab_stonename_2:NxLabel
		public var viewgroup_left2_2:NxViewGroup
		public var lab_succeedpercent_2:NxLabel
		public var lab_needmoney_2:NxLabel
		public var btn_star_2:NxButton
		public var parent3:MovieClip
		public var border_left_3:MovieClip
		public var lab_stonename_3:NxLabel
		public var viewgroup_left_3_1:NxViewGroup
		public var viewgroup_left_3_2:NxViewGroup
		public var viewgroup_left_3_3:NxViewGroup
		public var lab_succeedpercent_3:NxLabel
		public var lab_needmoney_3:NxLabel
		public var btn_star_3:NxButton
		
		public var parent4:MovieClip
		public var border_left_4:MovieClip
		public var lab_equipname_4:NxLabel
		public var viewgroup_left_4:NxViewGroup
		public var hole1_select_4:NxRadio
		public var hole2_select_4:NxRadio
		public var hole3_select_4:NxRadio
		public var hole4_select_4:NxRadio
		public var hole1_lab_4:NxLabel
		public var hole2_lab_4:NxLabel
		public var hole3_lab_4:NxLabel
		public var hole4_lab_4:NxLabel
		public var lab_succeedpercent_4:NxLabel
		public var lab_needmoney_4:NxLabel
		public var btn_star_4:NxButton
		
		public var parent5:MovieClip
		public var border_left_5:MovieClip
		public var lab_equipname_5:NxLabel
		public var viewgroup_left_5:NxViewGroup
		public var table_left_5:NxTable
		public var lab_succeedpercent_5:NxLabel
		public var lab_needequiplevel_5:NxLabel
		public var lab_losenumber_5:NxLabel
		public var bg_left1_5:MovieClip
		public var bg_left2_5:MovieClip
		public var lab_needmoney_5:NxLabel
		public var lab_getmoney_5:NxLabel
		public var btn_star_up_5:NxButton
		public var btn_star_down_5:NxButton
		public var btn_cd_5:NxButton
		
		public var parent6:MovieClip
		public var border_left_6:MovieClip
		public var lab_equipname_old_6:NxLabel
		public var viewgroup_old_6:NxViewGroup
		public var lab_equipname_new_6:NxLabel
		public var viewgroup_new_6:NxViewGroup
		public var table_left_6:NxTable
		public var lab_uplevel_6:NxLabel
		public var lab_succeedpercent_6:NxLabel
		public var bg_left_6:MovieClip
		public var select_stonelevel_6:MovieClip
		public var lab_stonelevel_6:NxLabel
		public var select_uplevel_6:MovieClip
		public var lab_needmoney_6:NxLabel
		public var select_free_6:MovieClip
		public var lab_free_6:NxLabel
		public var btn_star_6:NxButton
		public var hole1_lab_6:NxLabel
		
		public var parent7:MovieClip;
		public var border_left_7:MovieClip;
		public var viewgroup_left_7:NxViewGroup;
		public var lab_stonename_7:NxLabel;
		public var lab_needmoney_7:NxLabel;
		public var btn_star_7:NxButton;
		
		public var textSkin_left:MovieClip
		public var kuang_left:MovieClip
		public var textSkin_right:MovieClip
		public var kuang_right:MovieClip
		public var tab_up:NxTab
		public var text_left:NxText
		public var viewgroup_right:NxViewGroup
		public var tab_right:NxTab
		public var btn_pre:NxButton
		public var btn_next:NxButton
		public var page_down_bg:MovieClip
		public var page_down:NxLabel
		
		
		private var changeStrArray:Array;
		private var upTabClickID:int	=	4;
		private var oldTabClickID:int	=	-2
		private var myEquip:Object;
		private var packEquip:Object;
		private var rockEquip:Object;
		
		private var _autoSelect:Boolean	=	true;
		
		private var _model:ModelLocator;
		private var _bindManage:BindManage;
		//打孔
		private var _bindAddHole	:uint;
		//镶嵌栏
		private var _bindEnchase	:uint;
		//合成栏
		private var _bindCompose	:uint;
		//拆除栏
		private var _bindUnenchase	:uint;
		//升级
		private var _bindUpEquip	:uint;
		//保值
		private var _bindProtection	:uint; 
		//洗宝石
		private var _bindRockChange:uint;
		
		//功能显示对象容器
		private var _spaceArray					:Array
		//显示视图框
		private var _viewGoroupAll				:Array;		//全部显示框
		
		private var _menuItemList				:Array;		//弹出列表
		
		/***打孔*/
		public static var EQUIP_HOLD			:String		=	"EQUIP_HOLD";
		/***镶嵌*/
		public static var EQUIP_ENCHASE			:String		=	"EQUIP_ENCHASE";
		/***合成*/
		public static var EQUIP_COMPOSE			:String		=	"EQUIP_COMPOSE";
		/***拆解*/
		public static var EQUIP_UNENCHASE		:String		=	"EQUIP_UNENCHASE";
		/***升级*/
		public static var EQUIP_UP				:String		=	"EQUIP_UP";
		/***保值*/
		public static var EQUIP_PROTECTION		:String		=	"EQUIP_PROTECTION";
		/***保值*/
		public static var ROCK_CHANGE		:String		=	"ROCK_CHANGE";
		
		//打孔逻辑
		private var _equipStilettoLogic			:IEquipLogic
		private var _equipEnchaseLogic			:IEquipLogic;
		private var _equipComposeLogic			:IEquipLogic;
		private var _equipUnenchaseLogic		:IEquipLogic;
		private var _equipUpLoagic				:IEquipLogic;
		private var _equipProtectionLogic		:IEquipLogic;
		private var _rockChangeLogic			:IEquipLogic;
		private var _newEquipLogic				:IEquipLogic
		private var _logicArray:Array	
		//装备检索逻辑
		private var _equipLeach:EquipLeachLogic;
		
		private static var _self:NewItemChangeUI;
		
		private var _cuntrPage					:Number	=	0;
		private var _totalPage					:Number	=	0;
		private var _pageMax					:Number	=	18;
		private var _equipArray					:Array;
		
		public function NewItemChangeUI(popupUI:Boolean=true)
		{
			super(popupUI);
		}
		
		public static function getInstance():NewItemChangeUI
		{
			if(_self == null)
			{
				_self = new NewItemChangeUI();
			}
			return _self;
		}
		override public function Init():void
		{
			myEquip		=	{ };
			packEquip	=	{ };
			rockEquip	=	{ };
			myEquip["label"]				=	StaticIni.getSwfLangStr("NewItemChangeUIStr_26");
			myEquip["data"]					=	EquipLeachLogic.ROLE_EQUIP;
			
			packEquip["label"]				=	StaticIni.getSwfLangStr("NewItemChangeUIStr_27");
			packEquip["data"]				=	EquipLeachLogic.PACK_EQUIP;
			
			rockEquip["label"]				=	StaticIni.getSwfLangStr("NewItemChangeUIStr_28");
			rockEquip["data"]				=	EquipLeachLogic.PACK_ROCK;
			
			_viewGoroupAll					=	[viewgroup_left_1, viewgroup_left2_1, viewgroup_left2_2,viewgroup_left_3_1,
												viewgroup_left_3_2, viewgroup_left_3_3, viewgroup_left_4, viewgroup_left_5, 
												viewgroup_old_6, viewgroup_new_6, viewgroup_right, viewgroup_left_7];
												
			_bindManage						=	BindManage.getInstance();
			_model							=	ModelLocator.getInstance();
			_equipLeach						=	EquipLeachLogic.getInstance();
			
			_equipStilettoLogic				=	EquipStilettoLogic.getInstance(parent1);
			_equipEnchaseLogic				=	EquipEnchaseLogic.getInstance(parent2);
			_equipComposeLogic				=	EquipComposeLogic.getInstance(parent3);
			_equipUnenchaseLogic			=	EquipUnenchaseLogic.getInstance(parent4);
			_equipUpLoagic					=	EquipUpLogic.getInstance(parent5);
			_equipProtectionLogic			=	EquipProtectionLogic.getInstance(parent6);
			_rockChangeLogic				=	RockChangeLogic.getInstance(parent7)
			
			_logicArray						=	[_equipStilettoLogic, _equipEnchaseLogic, _equipComposeLogic, _equipUnenchaseLogic, _equipUpLoagic, _equipProtectionLogic,_rockChangeLogic];
			_spaceArray						=	[parent1, parent2, parent3, parent4, parent5, parent6, parent7];
			addTabItemLabel();
			clearSpaceBG();
			checkShowType(upTabClickID);
		}
		/**
		 * 添加强化类型页签显示内容
		 */
		private function addTabItemLabel():void
		{
			tab_up.clearItems();
			
			tab_up.addItem(StaticIni.getSwfLangStr("F_Gem_13201"),			-1,		EQUIP_HOLD);
			tab_up.addItem(StaticIni.getSwfLangStr("F_Gem_13202"),			-1,		EQUIP_ENCHASE);
			tab_up.addItem(StaticIni.getSwfLangStr("F_Gem_13203"),			-1,		EQUIP_COMPOSE);
			tab_up.addItem(StaticIni.getSwfLangStr("F_Gem_13204"),			-1,		EQUIP_UNENCHASE);
			tab_up.addItem(StaticIni.getSwfLangStr("Common_UpGrade"),		-1,		EQUIP_UP);
			tab_up.addItem(StaticIni.getSwfLangStr("UIStr_1001646"), 		-1,		EQUIP_PROTECTION);
			tab_up.addItem(StaticIni.getSwfLangStr("NewItemChangeUIStr_53"),-1,		ROCK_CHANGE);
		}
		/**
		 * 因为用的是容器组件,所以要去处背景
		 * 清除背景
		 */
		private function clearSpaceBG():void
		{
			for each (var item:MovieClip in _spaceArray) 
			{
				item.removeChildAt(0);
			}
		}
		/**
		 * 指定页签显示
		 * @param	val
		 */
		public function onShow(val:int):void
		{
			addListent();
			_autoSelect	=	false
			tab_up.selected = val;
			UIManage.getInstance().requestOpenUI(NewItemChangeUI.getInstance());
			_equipLeach.register(tab_up.dataProvider[tab_up.selected]["data"],
								tab_right.dataProvider[tab_right.selected]["data"],
								callFunction);
		}
		/**
		 * 根据页签的选择来判断所显示具体界面
		 * @param	val
		 */
		private function checkShowType(val:int):void
		{
			parent1.visible	=	false;
			parent2.visible	=	false;
			parent3.visible	=	false;
			parent4.visible	=	false;
			parent5.visible	=	false;
			parent6.visible	=	false;
			parent7.visible	=	false;
			
			for each (var item:IEquipLogic in _logicArray) 
			{
				item.removeAll();
			}
			tab_right.clearItems();
			
			switch(val)
			{
				case 0:
					_newEquipLogic			=	_equipStilettoLogic;
					parent1.visible			=	true;
					tab_right.dataProvider	=	[myEquip, packEquip];
					windowBG.title			=	StaticIni.getSwfLangStr("NewItemChangeUIStr_7");
					text_left.htmlStr		=	StaticIni.getSwfLangStr("F_Gem_13218");
					break;
				case 1:
					_newEquipLogic			=	_equipEnchaseLogic;
					parent2.visible			=	true;
					tab_right.dataProvider	=	[myEquip, packEquip, rockEquip];
					windowBG.title			=	StaticIni.getSwfLangStr("NewItemChangeUIStr_8");
					text_left.htmlStr		=	StaticIni.getSwfLangStr("F_Gem_13219");

					break;
				case 2:
					_newEquipLogic			=	_equipComposeLogic;
					parent3.visible			=	true;
					tab_right.dataProvider	=	[rockEquip];
					windowBG.title			=	StaticIni.getSwfLangStr("NewItemChangeUIStr_9");
					text_left.htmlStr		=	StaticIni.getSwfLangStr("F_Gem_13220");

					break;
				case 3:
					_newEquipLogic			=	_equipUnenchaseLogic;
					parent4.visible			=	true;
					tab_right.dataProvider	=	[myEquip, packEquip];
					windowBG.title			=	StaticIni.getSwfLangStr("NewItemChangeUIStr_10");
					text_left.htmlStr		=	StaticIni.getSwfLangStr("F_Gem_13221");

					break;
				case 4:
					_newEquipLogic			=	_equipUpLoagic;
					parent5.visible			=	true;
					tab_right.dataProvider	=	[myEquip, packEquip];
					windowBG.title			=	StaticIni.getSwfLangStr("NewItemChangeUIStr_11");
					text_left.htmlStr		=	StaticIni.getSwfLangStr("UIStr_1001348");
					break;
				case 5:
					_newEquipLogic			=	_equipProtectionLogic;
					parent6.visible			=	true;
					tab_right.dataProvider	=	[myEquip, packEquip];
					windowBG.title			=	StaticIni.getSwfLangStr("NewItemChangeUIStr_12");
					text_left.htmlStr		=	StaticIni.getSwfLangStr("UIStr_1001625");
					break;
				case 6:
					_newEquipLogic			=	_rockChangeLogic
					parent7.visible			=	true;
					tab_right.dataProvider	=	[rockEquip];
					windowBG.title			=	StaticIni.getSwfLangStr("NewItemChangeUIStr_54");
					text_left.htmlStr		=	StaticIni.getSwfLangStr("NewItemChangeUIStr_49");
					break;
			}
			bind(val);
			changeTabLabel();
		}
		/**
		 * 添加邦定视图
		 * @param	val
		 */
		private function bind(val:int):void
		{
			removeBind();
			switch(val)
			{
				case 0:
					_bindAddHole	=	_bindManage.BindView(_model.scene, getViewType(val), onAddItem, onRemoveItem);
					break;
				case 1:
					_bindEnchase	=	_bindManage.BindView(_model.scene, getViewType(val), onAddItem, onRemoveItem);
					break;
				case 2:
					_bindCompose	=	_bindManage.BindView(_model.scene, getViewType(val), onAddItem, onRemoveItem);
					break;
				case 3:
					_bindUnenchase	=	_bindManage.BindView(_model.scene, getViewType(val), onAddItem, onRemoveItem);
					break;
				case 4:
					_bindUpEquip	=	_bindManage.BindView(_model.scene,getViewType(val),onAddItem,onRemoveItem);
					break;
				case 5:
					_bindProtection	=	_bindManage.BindView(_model.scene,getViewType(val),onAddItem,onRemoveItem);
					break;
				case 6:
					_bindRockChange =	_bindManage.BindView(_model.scene,getViewType(val),onAddItem,onRemoveItem);
					break
			}
		}
		
		/**
		 * 解除邦定视图
		 */
		private function removeBind():void
		{
			_bindManage.UnbindView(View.VIEWPORT_ADDHOLE, _bindAddHole);
			_bindManage.UnbindView(View.VIEWPORT_ENCHASE, _bindEnchase);
			_bindManage.UnbindView(View.VIEWPORT_COMPOSE, _bindCompose);
			_bindManage.UnbindView(View.VIEWPORT_UNENCHASE, _bindUnenchase);
			_bindManage.UnbindView(View.VIEWPORT_EQUIPUPGRADE, _bindUpEquip);
			_bindManage.UnbindView(View.VIEWPORT_KEEPWORTH, _bindProtection);
			_bindManage.UnbindView(View.VIEWPORT_RANDOMSTONE, _bindRockChange);
		}
		/**
		 * 获取视图名
		 * @param	val
		 */
		private function getViewType(val:int):int
		{
			var viewName:int	=	-1;
			switch(val)
			{
				case 0:
					viewName	=	View.VIEWPORT_ADDHOLE;
					break;
				case 1:
					viewName	=	View.VIEWPORT_ENCHASE;
					break;
				case 2:
					viewName	=	View.VIEWPORT_COMPOSE;
					break;
				case 3:
					viewName	=	View.VIEWPORT_UNENCHASE;
					break;
				case 4:
					viewName	=	View.VIEWPORT_EQUIPUPGRADE;
					break;
				case 5:
					viewName	=	View.VIEWPORT_KEEPWORTH;
					break;
				case 6:
					viewName	=	View.VIEWPORT_RANDOMSTONE;
					break;
			}
			return	viewName;
		}
		/**
		 * 添加视图内容 
		 * @param objID
		 * @param obj
		 * @param data
		 */		
		private function onAddItem(objID:String,obj:BaseObject,data:*):void
		{
			_newEquipLogic.addEquip(obj);
		}
		/**
		 * 删除视图内容
		 * @param objID
		 * @param obj
		 * @param data
		 */		
		private function onRemoveItem(objID:String,obj:BaseObject,data:*):void
		{
			_newEquipLogic.removeEquip(obj);
		}

		/**
		 * 页签点击事件
		 * @param	e
		 */	
		private function upTabClickHandle(e:NxTabEvent):void 
		{
			if (e.target == tab_up) 
			{
				
				upTabClickID	=	e.item.index;
				checkShowType(upTabClickID);
			}
			else
			{
				var tabID:int	=	0;	
				switch(e.item.index)
				{
					case 0:
						tabID	=	101;
						break;
					case 1:
						tabID	=	102;
						break;
					case 2 :
						tabID	=	103;
						break;
				}
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CLICK_LABEL, tabID);
			}
			_equipLeach.register(tab_up.dataProvider[tab_up.selected]["data"],
								tab_right.dataProvider[tab_right.selected]["data"],
								callFunction);
		}
		/**
		 * 回调函数
		 * 显示身上，背包中所相应的物品
		 * @param	val
		 */
		public function callFunction(val:Array):void
		{
			
			_equipArray		=	checkArrayIndex(val);
			
			if((_equipArray.length % _pageMax) > 0){
				_totalPage		=	Math.floor(_equipArray.length / _pageMax);
			}else
			{
				_totalPage		=	Math.floor(_equipArray.length / _pageMax) -1;
			}
			if (_totalPage < 0) 
			{
				_totalPage = 0;
			}
			if (_cuntrPage > _totalPage) 
			{
				_cuntrPage = 0;
			}
			showPage()
			showItemEquip();
		}
		/**
		 * 因为新手引导的需要做的一次装备排序
		 * @param	val
		 * @return
		 */
		private function checkArrayIndex(val:Array):Array
		{
			//排序
			val = sortOnItem(val);
			var sceneID:int	=	_model.scene.Role.GetProperties("GuideFlag");
			if (0	==	sceneID) 
			{
				for (var i:int = 0; i < val.length; i++) 
				{
					var checkData:BaseObject	=	val[i] as BaseObject;
					var configID:String	=	checkData.GetProperties("ConfigID"); 
					if (configID == "13011809" ||	configID == "13012809" || configID == "13013809" ||
						configID == "13020809"	||	configID == "13015809" ||	configID == "13012801" ||
						configID == "13013801"	||	configID == "13011801" ||	configID == "13015801" ||
						configID == "13020801") 
					{
						var tempItem:BaseObject	=	val[0] as BaseObject;
						val[0]					=	val[i];
						val[i]					=	tempItem;
					}
				}
			}
			return	val;
		}
		private function sortOnItem(val:Array):Array
		{
			var length:int	=	val.length;
			var smallItem:BaseObject;
			for (var i:int = 0; i < length; i++) 
			{
				smallItem	=	val[i] as BaseObject;
				for (var j:int = i; j < length; j++) 
				{
					if (smallItem.GetProperties("WorldUID") > (val[j] as BaseObject).GetProperties("WorldUID")) 
					{
						smallItem	=	val[j] as BaseObject;
						val[j]		=	val[i];
						val[i]		=	smallItem;
					}
				}
			}
			return val
			
		}
		/**
		 * 显示页码
		 */
		private function showPage():void
		{
			btn_pre	.enabled	=	true;
			btn_next	.enabled	=	true;
			
			if(_cuntrPage >= _totalPage){
				btn_next.enabled = false;
			}
			
			if(_cuntrPage == 0){
				btn_pre.enabled = false;
			}
			page_down.htmlText	=	(_cuntrPage+1) + "/" + (_totalPage +1)
		}
		/**
		 * 添加图片
		 */
		private function showItemEquip():void
		{
			clearEquipView();
			var starIndex:int 	=	_pageMax * ( _cuntrPage + 1 );
			var _maxItem:int;
			if(starIndex  > _equipArray.length){			
				_maxItem	=	_equipArray.length;	
			}else{
				_maxItem	=	starIndex;
			}
			var index:int	=	0;
			for(var i:int  = _cuntrPage * _pageMax;	i < _maxItem;	i++)
			{
				//获取装备对象
				var itemMC	:MovieClip 	=	viewgroup_right.getItemByIndex(index);
				var equipClip:NxClip	=	new NxClip();
				equipClip.isCache		=	true;
				var data_:BaseObject	=	_equipArray[i] as BaseObject;
				equipClip.width			=	equipClip.height	=	40;
				equipClip.x				=	4;
				equipClip.y				=	4;
				if (data_.GetProperties("isEnable")) 
				{
					equipClip.filters	=	[];
				}
				else
				{
					equipClip.filters	=	[FilterUtil.GrayColorFilter]
				}
				itemMC["data"]			=	data_;
				equipClip.source		=	"res/items/icon_" + data_.GetProperties("Photo") + ".jpg";
				itemMC.addChild(equipClip);
				index++;
			}
		}
		/**
		 * 读取装备的特殊属性
		 * AddProp
		 * @return
		 */
		public function readSpecialProperty(proNum_:int,configObj_:ObjectData):String
		{
			var tempStr:String	=	"";
			var property	:String	=	"";
			if(proNum_ != -1 && configObj_!=null)
			{
				property	= configObj_.GetPropertiesEx("AddPropNo"+(proNum_+6));
				if(property != null && property != ""&&property !="0")
				{

					var addPropObj	:Object = StaticIni.getIniObj("AddProp");
					var propertyList : Array	=	addPropObj[property].split(",");
					//属性类型
					var type : String = propertyList[3];
					//属性值
					var value : int = propertyList[4];
					
					//有属性的时候
					if(type != null && type != "")
					{
						tempStr 	= StaticIni.getSwfLangStrVar("Item_" + type,[value]);
					}
					
				}
				else
				{
					tempStr	=	StaticIni.getSwfLangStr("F_Gem_13234");
				}
			}
			else
			{
				tempStr	=	StaticIni.getSwfLangStr("F_Gem_13233");
			}
			
			return tempStr;
		}
		/**
		 * 镶嵌属性数量 
		 * @param val
		 * @return 
		 * 
		 */		
		public function addPropNoNum(val:BaseObject):int
		{
			var propNum:int = 0;
			for(var i:int =6; i < 10; i++)
			{
				var propStr:String	=	val.GetProperties("AddPropNo" + i);
				if(propStr !=null && propStr != "" && propStr != "0")
				{
					propNum++;
				}
			}
			return propNum;
		}
		/**
		 * 设定最小的CD时间
		 * @param	val
		 */
		public function setMinCDTimer(val:Object):void
		{
			EquipUpLogic.getInstance(parent5).CDTimer(val)
		}
		/**
		 * 发送页签切换消息
		 */
		private function changeTabLabel():void
		{
			if (oldTabClickID	==	-2) 
			{
				oldTabClickID	=	upTabClickID;
			}
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SWITCH_ENHANSE_TAB, getViewType(oldTabClickID), getViewType(upTabClickID));
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CHANGE_ENCHASEPAGE, getViewType(upTabClickID));
			oldTabClickID	=	upTabClickID;
		}
		/**
		 * 清空右边装备显示框中的内容
		 */
		private function clearEquipView():void
		{
			var maxNum:int	=	viewgroup_right.col * viewgroup_right.row;
			for (var i:int = 0; i < maxNum; i++) 
			{
				//获取装备对象
				var itemMC	:MovieClip 	=	viewgroup_right.getItemByIndex(i);
				while(itemMC.numChildren > 1){
					itemMC.removeChildAt(1);
				}
				itemMC["data"] = null;
			}
		}
		/**
		 * 关闭窗口
		 * @param	e
		 */
		private function onClickClose(e:NxWindowEvent):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CLOSE_ENHANSE)
			UIManage.getInstance().requestHideUI(NewItemChangeUI.getInstance());
		}
		private function pageBtnClickHandle(e:MouseEvent):void
		{
			if (e.target == btn_next) 
			{
				_cuntrPage++;
				showPage()
				showItemEquip();
			}
			else if (e.target == btn_pre)
			{
				_cuntrPage--;
				showPage()
				showItemEquip();
			}
		}
		/**
		 * tips显示
		 * @param	e
		 */
		private function viewItemOverHandle(e:MouseEvent):void
		{
			var item:MovieClip	=	e.currentTarget as MovieClip;
			var bindType : int 
			var bindStatus : int
			var config:uint;
			var tObj:BaseObject = item.data as BaseObject;
			if(tObj!=null&&tObj.CheckProperties("ConfigID"))
			{
				bindType 	= (tObj as ObjectData).GetPropertiesEx("BindType");
				bindStatus 	= (tObj as ObjectData).GetPropertiesEx("BindStatus");
									
				if(tObj.CheckProperties("EquipType") && tObj.GetProperties("EquipType") != "")
				{
					TipsManage.ShowItemMaxTips(tObj,null);						
				}
				else
				{
					TipsManage.ShowItemTips(tObj.GetProperties("ConfigID"),bindType,bindStatus);
				}
			}
		}
		/**
		 * tips关闭
		 * @param	e
		 */
		private function viewItemOutHandle(e:MouseEvent):void
		{
			TipsManage.hideTips();
		}
		/**
		 * 点击视图
		 * @param	e
		 */
		private function viewItemClickHandle(e:MouseEvent):void
		{
			MenuList.hide();

			var clip:MovieClip		=	e.currentTarget as MovieClip;
			var tObj:ObjectData	=	clip.data;

			if (tObj == null) return;
			if (e.target.parent.parent	==	viewgroup_right) 
			{
				if (!tObj.GetProperties("isEnable")) 
				{
					return;
				}
				_menuItemList				=	[];
				var itemType:String			=	tObj.GetProperties("ItemType");
				var subItemType:String		=	tObj.GetProperties("SubItemType");
				if (tab_up.dataProvider[tab_up.selected]["data"]	==	EQUIP_ENCHASE) 
				{
					if (tab_right.dataProvider[tab_right.selected]["data"] != EquipLeachLogic.PACK_ROCK) 
					{
						//添加镶嵌物品
						getMenuListFunction(12, tObj);
					}
					else
					{
						//添加镶嵌宝石物品
						getMenuListFunction(13, tObj);
					}
				}
				else if (tab_up.dataProvider[tab_up.selected]["data"]	==	ROCK_CHANGE&&
					tab_right.dataProvider[tab_right.selected]["data"]	==	EquipLeachLogic.PACK_ROCK)
				{
					//添加熔炼时的宝石
					getMenuListFunction(11, tObj);
				}
				else
				{
					if (tab_up.dataProvider[tab_up.selected]["data"]	==	EQUIP_PROTECTION ) 
					{
						//保值时的菜单
						var holeCount:int			=	tObj.GetProperties("HoleCount");
						var intensityLevel:int		=	tObj.GetProperties("IntensityLevel");
						var checkProtectionData:BaseObject	=	(viewgroup_old_6.getItemByIndex(0) as MovieClip)["data"];
						if (checkProtectionData == null) 
						{
							if (holeCount == 0 && intensityLevel == 0) 
							{
								//添加保值目标物品
								getMenuListFunction(8, tObj);
							}
							else
							{
								//添加保值物品
								getMenuListFunction(5, tObj);
							}
						}
						else
						{
							if (holeCount == 0 && intensityLevel == 0) 
							{
								//添加保值目标物品
								getMenuListFunction(8, tObj);
							}
							else
							{
								//添加保值目标物品
								_menuItemList.push(StaticIni.getSwfLangStr("UIStr_1001646"));
								_menuItemList.push(StaticIni.getSwfLangStr("UIStr_1001479"))
								MenuList.ShowMenu(_menuItemList, menuListClickHandle, [tObj]);
							}
						}
					}
					else
					{
						//物品栏中的统一添加
						getMenuListFunction(tab_up.selected,tObj);
					}
				}
			}
			else if (e.target.parent.parent	==	viewgroup_old_6 || e.target.parent.parent	==	viewgroup_left2_1)
			{
				//镶嵌，保值时的取回物品
				getMenuListFunction(9,tObj)
			}
			else if (e.target.parent.parent	==	viewgroup_new_6 || e.target.parent.parent	==	viewgroup_left2_2)
			{
				//镶嵌，保值时的取回宝石与，保值目标物品
				getMenuListFunction(10,tObj)
			}
			else if(e.target.parent.parent is NxViewGroup)
			{
				//通一的取回物品，物品添加
				getMenuListFunction(7,tObj)
			}
		}
		/**
		 * 菜单列表点击事件
		 * 保值
		 * 保值目标
		 */
		private function menuListClickHandle(type:uint,clickData:*):void
		{
			var obj:ObjectData	=	clickData[0] as ObjectData;
			var menuStr:String	=	_menuItemList[type];
			switch(menuStr)
			{
				case StaticIni.getSwfLangStr("UIStr_1001646"):
					getMenuListFunction(5, obj);
					break;
				case StaticIni.getSwfLangStr("UIStr_1001479"):
					getMenuListFunction(8,obj)
					break;
			}
		}
		/**
		 * 0打孔
		 * 1镶嵌
		 * 2合成
		 * 3拆解
		 * 4升级
		 * 5保值
		 * 6添加
		 * 7取回物品
		 * 8保值目标
		 * 9取回原物品
		 * 10取回目标物品
		 * 11添加洗宝石
		 * 12添加镶嵌物品
		 * 13添加镶嵌宝石
		 * @param	val
		 * @return
		 */
		public function getMenuListFunction(val:int,viewData_:ObjectData):void
		{
			var itemData:BaseObject	=	viewData_ as BaseObject;
			var viewType:int		=	View.VIEWPORT_TOOL;
			var nowViewType:int		=	-1;
			if (itemData.CheckProperties("NowViewType")) 
			{
				nowViewType	=	itemData.GetProperties("NowViewType");
			}
			if (itemData.CheckProperties("ViewInt")) 
			{
				viewType		=	itemData.GetProperties("ViewInt");
			}
			var post:int			=	parseInt(itemData["ObjKey"]);
			var bindType:int		=	0;
			switch(val)
			{
				case 0:
				case 1:
				case 2:
				case 3:
				case 4:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_EQUIP_ENHANSE,getViewType(val),post,viewType);
					break;
				case 5:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_KEEPWORTH_SETEQUIP_SRC,getViewType(5),post,viewType);
					break;
				case 6:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_MOVEITEM, viewType, post, getViewType(1), 3);
					break;
				case 7:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CLEAR_ENHANSEBOX);
					break;
				case 8:
					//原物品如是绑定类型的，做出提示信息。
					var checkProtectionData:BaseObject	=	(viewgroup_old_6.getItemByIndex(0) as MovieClip)["data"];
					if (checkProtectionData == null) 
					{
						SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_KEEPWORTH_SETEQUIP_DEST,getViewType(5),post,viewType);
					}
					else
					{
						bindType	=	checkProtectionData.GetProperties("BindStatus");
						var nowBindType:int	=	itemData.GetProperties("BindStatus");
						if (bindType > 0 && nowBindType ==0) 
						{
							AlertUI.showAlert(StaticIni.getSwfLangStr("MessageUI_Notice"), StaticIni.getSwfLangStr("UIStr_1001693"), AlertUI.OK | AlertUI.CANCEL, function(type:int, str:String, clickData:*):void
							{
								if (type	==	AlertUI.OK)
								{
									SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_KEEPWORTH_SETEQUIP_DEST,getViewType(5),post,viewType);
								}
							})
						}
						else
						{
							SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_KEEPWORTH_SETEQUIP_DEST,getViewType(5),post,viewType);
						}
					}

					break;
				case 9:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_KEEPWORTH_BACK_BAG,1,nowViewType);
					break;
				case 10:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_KEEPWORTH_BACK_BAG,2,nowViewType);
					break;
				case 11:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_EQUIP_ENHANSE, getViewType(6), post, viewType);
					break;
				case 12:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_KEEPWORTH_SETEQUIP_SRC,getViewType(1),post,viewType);
					break;
				case 13:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_KEEPWORTH_SETEQUIP_DEST,getViewType(1),post,viewType);
					break;
			}
		}
		/**
		 * 清除所有显示信息
		 */
		private function clearAll():void
		{
			for each (var viewBox:NxViewGroup in _viewGoroupAll) 
			{
				var itemMc:MovieClip	=	viewBox.getItemByIndex(0);	
				itemMc["data"]= null;
				while(itemMc.numChildren > 1)
				{
					itemMc.removeChildAt(1);
				}
			}

		}
		
		/**
		 * 添加侦听事件
		 */
		private function addListent():void
		{
			tab_up		.addEventListener(	NxTabEvent.TAB_CLICK, 				upTabClickHandle);
			tab_right	.addEventListener(	NxTabEvent.TAB_CLICK,				upTabClickHandle)
			windowBG	.addEventListener(	NxWindowEvent.WINDOW_CLOSE,			onClickClose);
			btn_next	.addEventListener(MouseEvent.CLICK, pageBtnClickHandle);
			btn_pre		.addEventListener(MouseEvent.CLICK, pageBtnClickHandle);
			for each (var item:NxViewGroup in _viewGoroupAll) 
			{
				item.addItemsEvent(MouseEvent.MOUSE_OVER, viewItemOverHandle);
				item.addItemsEvent(MouseEvent.MOUSE_OUT, viewItemOutHandle);
				item.addItemsEvent(MouseEvent.CLICK, viewItemClickHandle);
			}
		}
		/**
		 * 关闭侦听事件
		 */
		private function removeListent():void
		{
			tab_up		.removeEventListener(	NxTabEvent.TAB_CLICK, 				upTabClickHandle);
			tab_right	.removeEventListener(	NxTabEvent.TAB_CLICK,				upTabClickHandle);
			windowBG	.removeEventListener(	NxWindowEvent.WINDOW_CLOSE,			onClickClose);
			btn_next	.removeEventListener(	MouseEvent.CLICK, 					pageBtnClickHandle);
			btn_pre		.removeEventListener(	MouseEvent.CLICK, 					pageBtnClickHandle);
			for each (var item:NxViewGroup in _viewGoroupAll) 
			{
				item.removeItemsEvent(MouseEvent.MOUSE_OVER, 						viewItemOverHandle);
				item.removeItemsEvent(MouseEvent.MOUSE_OUT, 						viewItemOutHandle);
				item.removeItemsEvent(MouseEvent.CLICK, 							viewItemClickHandle);
			}
		}
		
		override protected function	BeforeShow():void
		{
			addListent();
			if (_autoSelect) 
			{
				tab_up.selected = upTabClickID;
			}
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_GET_BEST_CD,3);
			//NewModifiedChooseUI.getInstance().checkObjectShow();
		}
		
		override protected function	AfterHide():void
		{
			_autoSelect		=	true
			upTabClickID	=	4
			removeListent();
		}
		
	}

}